import javax.swing.*;
import java.awt.event.*;

public class tableUI extends JFrame {
	
	private JPanel tableTestPanel; //test
	private JButton tableBackButton; // back button
	private JButton gridFromTable; // button that links to grid from the table
	final int WINDOW_WIDTH = 800;
	final int WINDOW_HEIGHT = 800;
	public gridUI grid;
	public initUI init;
	
	public tableUI(initUI initial){
		
		setTitle("Table"); // sets window title
		setSize(WINDOW_WIDTH, WINDOW_HEIGHT); // sets window size
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // close when red X is clicked
		buildTableTestPanel();
		add(tableTestPanel);
		
		init = initial;
	}
	
	private void buildTableTestPanel(){
		
		tableBackButton = new JButton("Back to Menu"); // creates back to menu button
		tableBackButton.addActionListener(new backListener()); //adds listener to back to menu button
		gridFromTable = new JButton("Grid"); // creates table button
		gridFromTable.addActionListener(new backListener()); // adds listener to table button
		
		tableTestPanel = new JPanel(); // creates panel
		tableTestPanel.add(tableBackButton); // adds back to menu button
		tableTestPanel.add(gridFromTable); // adds grid button
	}
	
	private class backListener implements ActionListener{
		
		public void actionPerformed(ActionEvent e){
			
			if (e.getSource() == tableBackButton){ // if back button was pressed
				setVisible(false); // remove table visibility
				init.setVisible(true); // make initial UI visible
			}
			else if(e.getSource() == gridFromTable){ // if grid button was pressed
				
				setVisible(false); // remove table visibility
				grid.setVisible(true); // make grid visible
			}
		}
	}

}
